package com.warren.gulimall.order.vo;

import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 订单确认页面需要用到的数据
 * @author sunziren
 * @date 2021/9/13 14:56
 */
public class OrderConfirmVo {

    //收获地址 ums_member_receive_address 表
    @Setter
    @Getter
    List<MemberAddressVo> address;

    //所有选中的购物项目
    @Setter @Getter
    List<OrderItemVo> items;

    //防止重复下单的令牌
    @Getter @Setter
    String orderToken;

    //发票......

    //优惠券信息
    @Setter @Getter
    Integer integration;

    //指定SKU是否有库存
    @Setter @Getter
    Map<Long,Boolean> stocks;

    //订单总额
    //BigDecimal total;
    public BigDecimal getTotal(){
        BigDecimal sum = new BigDecimal("0");
        if(items!=null){
            for (OrderItemVo item : items) {
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount()));
                sum = sum.add(multiply);
            }
        }
        return sum;
    }

    //应付价格
    //BigDecimal payPrice;
    public BigDecimal getPayPrice(){
        return getTotal();
    }

    public Integer getCount(){
        Integer i = 0;
        if(items!=null){
            for (OrderItemVo item : items) {
                i+=item.getCount();
            }
        }
        return i;
    }

}

